home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / sortdemo.zip / SDDISP.INC < prev    next >
Text File  |  1992-04-15  |  18KB  |  520 lines

  1. (*
  2. ╔═══════════════════════════════════════════════════════════════════════════╗
  3. ║ Turbo Pascal 6.0 Include File : SDDISP.INC                                ║
  4. ╟───────────────────────────────────────────────────────────────────────────╢
  5. ║ Program : SORTDEMO.PAS                                                    ║
  6. ╟───────────────────────────────────────────────────────────────────────────╢
  7. ║ Version : 1.0                                                             ║
  8. ╟───────────────────────────────────────────────────────────────────────────╢
  9. ║ Copyright (c) 1992  by  Jon S. Russell                                    ║
  10. ╟───────────────────────────────────────────────────────────────────────────╢
  11. ║ Info-display and menuing routines for SORTDEMO.PAS                        ║
  12. ╚═══════════════════════════════════════════════════════════════════════════╝
  13.                                                                            *)
  14. procedure ShadowText (    Msg        : string;
  15.                           Col1, Col2 : word;
  16.                           x, y       : integer);
  17. var
  18.   OldCol : word;
  19.  
  20. begin  (* ShadowText *)
  21.   OldCol := GetColor;
  22.   SetColor(Col2);
  23.   OutTextXY(x-1,y+1,Msg);
  24.   SetColor(Col1);
  25.   OutTextXY(x,y,Msg);
  26.   SetColor(OldCol);
  27. end;   (* ShadowText *)
  28.  
  29. (*─────────────────────────────────────────────────────────────────────────*)
  30.  
  31. procedure TitleScreen;
  32. begin  (* TitleScreen *)
  33.   SetTextStyle(SmallFont, HorizDir, 6);
  34.   SetTextJustify(CenterText, TopText);
  35.   ShadowText('SortDemo', 9,1,160,65);
  36.   SetTextStyle(SmallFont, HorizDir, 4);
  37.   ShadowText('ver 1.0',9,1,160,85);
  38.   SetTextStyle(SmallFont, HorizDir, 3);
  39.   ShadowText('by',9,1,160,100);
  40.   SetTextStyle(SmallFont, HorizDir, 5);
  41.   ShadowText('Jon S. Russell',9,1,160,115);
  42.  
  43.   SetTextStyle(SmallFont, HorizDir, 4);
  44.   ShadowText('press any key...',10,2,160,185);
  45.   FlushAndWait;
  46.   ClearDevice;
  47. end;   (* TitleScreen *)
  48.  
  49. (*─────────────────────────────────────────────────────────────────────────*)
  50.  
  51. procedure Menu (var Info : InfoType);
  52. var
  53.   t : byte;
  54.  
  55. const
  56.   Mx1 =  10; My1 =  30;  Sx1 =  10; Sy1 = 160;
  57.   Mx2 = 310; My2 = 150;  Sx2 = 310; Sy2 = 180;
  58.  
  59.   (*───────────────────────────────────────────────────────────────────────*)
  60.  
  61.   procedure DrawSlider (TopX, TopY, Size, Index : integer);
  62.  
  63.   begin  (* DrawSlider *)
  64.     SetFillStyle(SolidFill, LightGray);
  65.     Bar(TopX, TopY, TopX+10, TopY+Size*10);
  66.     FillEllipse(TopX+5, TopY, 5, 2);
  67.     FillEllipse(TopX+5, TopY+Size*10, 5, 2);
  68.     SetFillStyle(SolidFill, Red);
  69.     Bar(TopX+2, TopY+(Index-1)*10+2, TopX+8, TopY+(Index-1)*10+8);
  70.   end;   (* DrawSlider *)
  71.  
  72.   (*───────────────────────────────────────────────────────────────────────*)
  73.  
  74.   procedure XSizeSlider ( index : word);
  75.   begin  (* XSizeSlider *)
  76.     case index of
  77.       20 : DrawSlider(Mx1+10, My1+20, 4, 1);
  78.       40 : DrawSlider(Mx1+10, My1+20, 4, 2);
  79.       80 : DrawSlider(Mx1+10, My1+20, 4, 3);
  80.      160 : DrawSlider(Mx1+10, My1+20, 4, 4);
  81.     end; (* case *)
  82.   end;   (* XSizeSlider *)
  83.  
  84.   (*───────────────────────────────────────────────────────────────────────*)
  85.  
  86.   procedure YSizeSlider ( index : word);
  87.   begin  (* YSizeSlider *)
  88.     case index of
  89.       1 : DrawSlider(Mx1+64, My1+20, 9, 1);
  90.       2 : DrawSlider(Mx1+64, My1+20, 9, 2);
  91.       4 : DrawSlider(Mx1+64, My1+20, 9, 3);
  92.       5 : DrawSlider(Mx1+64, My1+20, 9, 4);
  93.       8 : DrawSlider(Mx1+64, My1+20, 9, 5);
  94.      10 : DrawSlider(Mx1+64, My1+20, 9, 6);
  95.      20 : DrawSlider(Mx1+64, My1+20, 9, 7);
  96.      25 : DrawSlider(Mx1+64, My1+20, 9, 8);
  97.      50 : DrawSlider(Mx1+64, My1+20, 9, 9);
  98.     end; (* case *)
  99.   end;   (* YSizeSlider *)
  100.  
  101.   (*───────────────────────────────────────────────────────────────────────*)
  102.  
  103.   procedure MethodSlider ( index : MethodType);
  104.   begin  (* MethodSlider *)
  105.     DrawSlider(Mx1+110, My1+20, NumTitles, Ord(index)+1);
  106.   end;   (* MethodSlider *)
  107.  
  108.   (*───────────────────────────────────────────────────────────────────────*)
  109.  
  110.   procedure FileSlider ( index : boolean);
  111.   begin  (* FileSlider *)
  112.     case index of
  113.       true  : DrawSlider(Mx1+230, My1+20, 2, 1);
  114.       false : DrawSlider(Mx1+230, My1+20, 2, 2);
  115.     end; (* case *)
  116.   end;   (* FileSlider *)
  117.  
  118.   (*───────────────────────────────────────────────────────────────────────*)
  119.  
  120.   procedure OperationSlider ( index : OperationType);
  121.   begin  (* OperationSlider *)
  122.     DrawSlider(Mx1+230, My1+70, 3, Ord(index)+1);
  123.   end;   (* OperationSlider *)
  124.  
  125.   (*───────────────────────────────────────────────────────────────────────*)
  126.  
  127.   procedure ASize ( Len : word);
  128.   var
  129.     s : string;
  130.  
  131.   begin  (* ASize *)
  132.     SetFillStyle(SolidFill, Blue);
  133.     bar(Sx1+80, Sy1+5, Sx1+120, Sy1+15);
  134.     str(Len:5, s);
  135.     OutTextXY(Sx1+80, Sy1+5, s);
  136.   end;   (* ASize *)
  137.  
  138.   (*───────────────────────────────────────────────────────────────────────*)
  139.  
  140.   procedure AStatus ( Sorted : boolean);
  141.   var
  142.     s : string;
  143.  
  144.   begin  (* AStatus *)
  145.     SetFillStyle(SolidFill, Blue);
  146.     Bar(Sx1+235, Sy1+5, Sx1+290, Sy1+15);
  147.     if Sorted
  148.       then s := 'sorted   '
  149.       else s := 'unsorted';
  150.     OutTextXY(Sx1+240, Sy1+5, s);
  151.   end;   (* AStatus *)
  152.  
  153.   (*───────────────────────────────────────────────────────────────────────*)
  154.  
  155.   procedure DoMenu (var Info : InfoType);
  156.   type
  157.     OpSet = (XSize,YSize,Method,StatFile,Operation);
  158.  
  159.   var
  160.     OldOp : OpSet;
  161.     NewOp : OpSet;
  162.  
  163.     (*─────────────────────────────────────────────────────────────────────*)
  164.  
  165.     procedure NextOp (var Op : OpSet);
  166.     begin  (* NextOp *)
  167.       if Op <> Operation
  168.         then Op := Succ(Op)
  169.         else Op := XSize;
  170.     end;   (* NextOp *)
  171.  
  172.     (*─────────────────────────────────────────────────────────────────────*)
  173.  
  174.     procedure PrevOp (var Op : OpSet);
  175.     begin  (* PrevOp *)
  176.       if Op <> XSize
  177.         then Op := Pred(Op)
  178.         else Op := Operation;
  179.     end;   (* PrevOp *)
  180.  
  181.     (*─────────────────────────────────────────────────────────────────────*)
  182.  
  183.     procedure HighLight ( OldOp, NewOp : OpSet);
  184.     begin  (* HighLight *)
  185.       case OldOp of
  186.         XSize     : ShadowText('X-size',    LightGray,Blue,Mx1+ 10,My1+ 5);
  187.         YSize     : ShadowText('Y-size',    LightGray,Blue,Mx1+ 60,My1+ 5);
  188.         Method    : ShadowText('Method',    LightGray,Blue,Mx1+110,My1+ 5);
  189.         StatFile  : ShadowText('Stats file',LightGray,Blue,Mx1+230,My1+ 5);
  190.         Operation : ShadowText('Operation', LightGray,Blue,Mx1+230,My1+55);
  191.       end; (* case *)
  192.  
  193.       case NewOp of
  194.         XSize     : ShadowText('X-size',    White,DarkGray,Mx1+ 10,My1+ 5);
  195.         YSize     : ShadowText('Y-size',    White,DarkGray,Mx1+ 60,My1+ 5);
  196.         Method    : ShadowText('Method',    White,DarkGray,Mx1+110,My1+ 5);
  197.         StatFile  : ShadowText('Stats file',White,DarkGray,Mx1+230,My1+ 5);
  198.         Operation : ShadowText('Operation', White,DarkGray,Mx1+230,My1+55);
  199.       end; (* case *)
  200.     end;   (* HighLight *)
  201.  
  202.     (*─────────────────────────────────────────────────────────────────────*)
  203.  
  204.     procedure DecSet (var Info : InfoType;
  205.                           Op   : OpSet);
  206.     begin  (* DecSet *)
  207.       case Op of
  208.         XSize     : begin
  209.                       case Info.xElems of
  210.                         20 : Info.xElems := 160;
  211.                         40 : Info.xElems :=  20;
  212.                         80 : Info.xElems :=  40;
  213.                        160 : Info.xElems :=  80;
  214.                       end; (* case *)
  215.                       XSizeSlider(Info.xElems);
  216.                       Info.Len := Info.xElems*Info.yElems;
  217.                       LoadArray(Info);
  218.                       ASize(Info.Len);
  219.                       AStatus(Info.Sorted);
  220.                     end;
  221.         YSize     : begin
  222.                       case Info.yElems of
  223.                          1 : Info.yElems := 50;
  224.                          2 : Info.yElems :=  1;
  225.                          4 : Info.yElems :=  2;
  226.                          5 : Info.yElems :=  4;
  227.                          8 : Info.yElems :=  5;
  228.                         10 : Info.yElems :=  8;
  229.                         20 : Info.yElems := 10;
  230.                         25 : Info.yElems := 20;
  231.                         50 : Info.yElems := 25;
  232.                       end; (* case *)
  233.                       YSizeSlider(Info.yElems);
  234.                       Info.Len := Info.xElems*Info.yElems;
  235.                       LoadArray(Info);
  236.                       ASize(Info.Len);
  237.                       AStatus(Info.Sorted);
  238.                     end;
  239.         Method    : begin
  240.                       if Info.Method <> Bubble
  241.                         then Info.Method := pred(Info.Method)
  242.                         else Info.Method := Heap;
  243.                       MethodSlider(Info.Method);
  244.                     end;
  245.         StatFile  : begin
  246.                       if Info.Save
  247.                         then Info.Save := false
  248.                         else Info.Save := true;
  249.                       FileSlider(Info.Save);
  250.                     end;
  251.         Operation : begin
  252.                       if Info.Operation <> Mix
  253.                         then Info.Operation := pred(Info.Operation)
  254.                         else Info.Operation := Quit;
  255.                       OperationSlider(Info.Operation);
  256.                     end;
  257.       end; (* case *)
  258.     end;   (* DecSet *)
  259.  
  260.     (*─────────────────────────────────────────────────────────────────────*)
  261.  
  262.     procedure IncSet (var Info : InfoType;
  263.                           Op   : OpSet);
  264.     begin  (* IncSet *)
  265.       case Op of
  266.         XSize     : begin
  267.                       case Info.xElems of
  268.                         20 : Info.xElems :=  40;
  269.                         40 : Info.xElems :=  80;
  270.                         80 : Info.xElems := 160;
  271.                        160 : Info.xElems :=  20;
  272.                       end; (* case *)
  273.                       XSizeSlider(Info.xElems);
  274.                       Info.len := Info.xElems*Info.yElems;
  275.                       LoadArray(Info);
  276.                       ASize(Info.Len);
  277.                       AStatus(Info.Sorted);
  278.                     end;
  279.         YSize     : begin
  280.                       case Info.yElems of
  281.                          1 : Info.yElems :=  2;
  282.                          2 : Info.yElems :=  4;
  283.                          4 : Info.yElems :=  5;
  284.                          5 : Info.yElems :=  8;
  285.                          8 : Info.yElems := 10;
  286.                         10 : Info.yElems := 20;
  287.                         20 : Info.yElems := 25;
  288.                         25 : Info.yElems := 50;
  289.                         50 : Info.yElems :=  1;
  290.                       end; (* case *)
  291.                       YSizeSlider(Info.yElems);
  292.                       Info.Len := Info.xElems*Info.yElems;
  293.                       LoadArray(Info);
  294.                       ASize(Info.Len);
  295.                       AStatus(Info.Sorted);
  296.                     end;
  297.         Method    : begin
  298.                       if Info.Method <> Heap
  299.                         then Info.Method := succ(Info.Method)
  300.                         else Info.Method := Bubble;
  301.                       MethodSlider(Info.Method);
  302.                     end;
  303.         StatFile  : begin
  304.                       if Info.Save
  305.                         then Info.Save := false
  306.                         else Info.Save := true;
  307.                       FileSlider(Info.Save);
  308.                     end;
  309.         Operation : begin
  310.                       if Info.Operation <> Quit
  311.                         then Info.Operation := succ(Info.Operation)
  312.                         else Info.Operation := Mix;
  313.                       OperationSlider(Info.Operation);
  314.                     end;
  315.       end; (* case *)
  316.     end;   (* IncSet *)
  317.  
  318.     (*─────────────────────────────────────────────────────────────────────*)
  319.  
  320.   begin  (* DoMenu *)
  321.     OldOp := Operation;
  322.     NewOp := Operation;
  323.     HighLight (OldOp, NewOp);
  324.     FlushKeyBuffer;
  325.  
  326.     repeat
  327.       GetKey(KeyRec);
  328.       if KeyRec.Extended
  329.         then
  330.           begin
  331.             case KeyRec.Ch of
  332.               LfArrowKey : PrevOp(NewOp);
  333.               RtArrowKey : NextOp(NewOp);
  334.               UpArrowKey : DecSet(Info, NewOp);
  335.               DnArrowKey : IncSet(Info, NewOp);
  336.             end; (* case *)
  337.           end
  338.         else
  339.           begin
  340.             case KeyRec.Ch of
  341.               'x','X' : NewOp := XSize;
  342.               'y','Y' : NewOp := YSize;
  343.               'm','M' : NewOp := Method;
  344.               's','S' : NewOp := StatFile;
  345.               'o','O' : NewOp := Operation;
  346.             end; (* case *)
  347.           end;
  348.  
  349.       if OldOp <> NewOp then Highlight(OldOp, NewOp);
  350.       OldOp := NewOp;
  351.     until ((KeyRec.Extended = false) and (KeyRec.Ch = EnterKey));
  352.   end;   (* DoMenu *)
  353.  
  354.   (*───────────────────────────────────────────────────────────────────────*)
  355.  
  356. begin  (* Menu *)
  357.   ClearDevice;
  358.   DrawPanel(Mx1,My1,Mx2,My2, Blue, LightGray, DarkGray, 2);
  359.   DrawPanel(Sx1,Sy1,Sx2,Sy2, Blue, LightGray, DarkGray, 2);
  360.  
  361.   SetTextStyle(SmallFont, HorizDir, 4);
  362.   SetTextJustify(LeftText, TopText);
  363.   SetColor(LightGray);
  364.  
  365.   OutTextXY(Mx1+10, My1+ 5, 'X-size');
  366.   OutTextXY(Mx1+27, My1+20, ' 20');
  367.   OutTextXY(Mx1+27, My1+30, ' 40');
  368.   OutTextXY(Mx1+27, My1+40, ' 80');
  369.   OutTextXY(Mx1+27, My1+50, '160');
  370.   XSizeSlider(Info.xElems);
  371.  
  372.   OutTextXY(Mx1+60, My1+  5, 'Y-size');
  373.   OutTextXY(Mx1+77, My1+ 20, '  1');
  374.   OutTextXY(Mx1+77, My1+ 30, '  2');
  375.   OutTextXY(Mx1+77, My1+ 40, '  4');
  376.   OutTextXY(Mx1+77, My1+ 50, '  5');
  377.   OutTextXY(Mx1+77, My1+ 60, '  8');
  378.   OutTextXY(Mx1+77, My1+ 70, ' 10');
  379.   OutTextXY(Mx1+77, My1+ 80, ' 20');
  380.   OutTextXY(Mx1+77, My1+ 90, ' 25');
  381.   OutTextXY(Mx1+77, My1+100, ' 50');
  382.   YSizeSlider(Info.yElems);
  383.  
  384.   OutTextXY(Mx1+110, My1+ 5, 'Method');
  385.   for t := 1 to NumTitles do
  386.     OutTextXY(Mx1+127, My1+10+t*10, SortTitles[t]);
  387.   MethodSlider(Info.Method);
  388.  
  389.   OutTextXY(Mx1+230, My1+5, 'Stats file');
  390.   OutTextXY(Mx1+245, My1+20, 'yes');
  391.   OutTextXY(Mx1+245, My1+30, 'no');
  392.   FileSlider(Info.Save);
  393.  
  394.   OutTextXY(Mx1+230, My1+55, 'Operation');
  395.   OutTextXY(Mx1+245, My1+70, 'mix');
  396.   OutTextXY(Mx1+245, My1+80, 'sort');
  397.   OutTextXY(Mx1+245, My1+90, 'quit');
  398.   OperationSlider(Info.Operation);
  399.  
  400.  
  401.   OutTextXY(Sx1+10, Sy1+5, 'Array-size:');
  402.   ASize(Info.Len);
  403.   OutTextXY(Sx1+160, Sy1+5, 'Array-status:');
  404.   AStatus(Info.Sorted);
  405.  
  406.   DoMenu(Info);
  407. end;   (* Menu *)
  408.  
  409. (*─────────────────────────────────────────────────────────────────────────*)
  410.  
  411. procedure ShowAnalysis (var Info  : InfoType;
  412.                             Start : TimeDateType;
  413.                             Stop  : TimeDateType;
  414.                             Diff  : DiffType);
  415. const
  416.   Ax1 = 20;  Ax2 = 300;
  417.   Ay1 = 30;  Ay2 = 170;
  418.  
  419. var
  420.   s1, s2 : string;
  421.  
  422.   (*───────────────────────────────────────────────────────────────────────*)
  423.  
  424.   function Num2Str ( Num    : integer;
  425.                      Digits : byte;
  426.                      Fill   : boolean) : string;
  427.   var
  428.     S : string;
  429.  
  430.   begin (* Num2Str *)
  431.     str(Num:Digits, S);
  432.     if Fill then
  433.       while (pos(' ',S) > 0) do
  434.         S[pos(' ',S)] := '0';
  435.     Num2Str := S;
  436.   end;  (* Num2Str *)
  437.  
  438.   (*───────────────────────────────────────────────────────────────────────*)
  439.  
  440. begin  (* ShowAnalysis *)
  441.   ClearDevice;
  442.   DrawPanel(Ax1,Ay1,Ax2,Ay2, Blue, LightGray, DarkGray, 2);
  443.  
  444.   SetTextStyle(SmallFont, HorizDir, 7);
  445.   SetTextJustify(CenterText, TopText);
  446.   ShadowText('Analysis', LightRed, Red, 160, Ay1+5);
  447.  
  448.   SetTextStyle(SmallFont, HorizDir, 4);
  449.  
  450.   SetTextJustify(LeftText, TopText);
  451.   s1 := 'Sort method: ';
  452.   s2 := SortTitles[Ord(Info.Method)+1];
  453.   SetColor(LightGray);
  454.   OutTextXY(Ax1+10, Ay1+30, s1);
  455.   SetColor(White);
  456.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+30, s2);
  457.  
  458.   s1 := 'Array size: [';
  459.   s2 := Num2Str(Info.xElems, 3, false);
  460.   SetColor(LightGray);
  461.   OutTextXY(Ax1+10, Ay1+50, s1);
  462.   SetColor(White);
  463.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  464.   s1 := s1 + s2;
  465.   s2 := ',';
  466.   SetColor(LightGray);
  467.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  468.   s1 := s1 + s2;
  469.   s2 := Num2Str(Info.yElems, 3, false);
  470.   SetColor(White);
  471.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  472.   s1 := s1 + s2;
  473.   s2 := '] = ';
  474.   SetColor(LightGray);
  475.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  476.   s1 := s1 + s2;
  477.   s2 := Num2Str(Info.Len, 4, false);
  478.   SetColor(White);
  479.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  480.   s1 := s1 + s2;
  481.   s2 := ' elements';
  482.   SetColor(LightGray);
  483.   OutTextXY(Ax1+10+TextWidth(s1), Ay1+50, s2);
  484.  
  485.  
  486.   SetTextJustify(LeftText, TopText);
  487.   SetColor(LightGray);
  488.   OutTextXY(Ax1+5, Ay1+70, 'Start time:');
  489.   OutTextXY(Ax1+5, Ay1+80, 'Stop time:');
  490.  
  491.   SetTextJustify(RightText, TopText);
  492.   SetColor(White);
  493.   OutTextXY(Ax2-10, Ay1+70, TimeDate2Str(Start));
  494.   OutTextXY(Ax2-10, Ay1+80, TimeDate2Str(Stop));
  495.  
  496.   SetTextJustify(LeftText, TopText);
  497.   SetColor(LightGray);
  498.   OutTextXY(Ax1+5, Ay1+95, 'Sort time...');
  499.   SetTextJustify(RightText, TopText);
  500.   OutTextXY(Ax1+120, Ay1+95, 'Days');
  501.   OutTextXY(Ax1+155, Ay1+95, 'Hrs');
  502.   OutTextXY(Ax1+190, Ay1+95, 'Mins');
  503.   OutTextXY(Ax1+225, Ay1+95, 'Secs');
  504.   OutTextXY(Ax1+260, Ay1+95, '100s');
  505.   SetColor(White);
  506.   OutTextXY(Ax1+120, Ay1+105, Num2Str(Diff.Days, 2, false));
  507.   OutTextXY(Ax1+155, Ay1+105, Num2Str(Diff.Hours, 2, true));
  508.   OutTextXY(Ax1+190, Ay1+105, Num2Str(Diff.Minutes, 2, true));
  509.   OutTextXY(Ax1+225, Ay1+105, Num2Str(Diff.Seconds, 2, true));
  510.   OutTextXY(Ax1+260, Ay1+105, Num2Str(Diff.Sec100s, 2, true));
  511.  
  512.   if Info.Save then AnalysisToFile(Info, Start, Stop, Diff);
  513.  
  514.   SetTextJustify(CenterText, TopText);
  515.   ShadowText('press any key to continue', LightGreen, Green, 160, Ay2-15);
  516.   FlushAndWait;
  517. end;   (* ShowAnalysis *)
  518.  
  519. (*─────────────────────────────────────────────────────────────────────────*)
  520.